#!/bin/bash
#
# This script should help view only a single printing of
# a commands output as logged by procwatch.sh, such as
# netstat or top, assuming they print an empty line after
# each block of logging.
#
# Usage:
#    -- The first argument is the log filename, e.g. "20130423.top.txt"
#    -- The second argument is a time in the format "hh:mm:", e.g. "16:30:". This can
#       be anything that uniquely identifies the start of the block of logging.

searchFile=$1
searchTime=$2

[[ -z "$searchFile" ]] && read -e -p "Enter file to search: " searchFile
[[ -z "$searchTime" ]] && read -e -p "Enter 24hr time value with trailing ':' (e.g. 16:30: ): " searchTime

randChars=`cat /dev/urandom|tr -dc a-zA-Z0-9|fold -w 8|head -1`

echo
grep -A10000 "$searchTime" "$searchFile"|sed -e "0,/^$/s//$randChars/;/^$/ q"|sed "s/$randChars//"

exit
